import pandas as pd

def feature_engineering(data):
    """
    统一的特征工程函数，用于所有模型
    """
    # 创建新特征
    data['YearsAtCompany_adj'] = data['YearsAtCompany'].replace(0, 0.5)
    data['Manager Stability'] = data['YearsWithCurrManager'] / data['YearsAtCompany_adj']
    data['Prom Stagnation'] = data['YearsSinceLastPromotion'] / data['YearsAtCompany_adj']
    data['Avg Salary Hike Percentage'] = data['PercentSalaryHike'] / data['YearsAtCompany_adj']
    data['MonNum'] = data['MonthlyIncome'] / (data['TotalWorkingYears'] + 1)

    # 删除不必要的列
    data = data.drop(['EmployeeNumber', 'Over18', 'StandardHours', 'YearsAtCompany_adj'], axis=1)

    return data